# -*- coding: utf-8 -*-
# !/usr/bin/env python
from utils.mysql_utils import query_to_list


def query_env_soft(env_id=''):
    sql_parameter = []

    if env_id:
        sql_fragment = "WHERE b.env_id = %s"
        sql_parameter.append(env_id)
    else:
        sql_fragment = ''

    sql = """
    SELECT *
    FROM soft_management a
    LEFT JOIN hosts_management b ON a.host_id = b.host_id AND b.`status` = 1
    %s
    AND a.`status` = 1
    """%sql_fragment
    data = query_to_list(sql, sql_parameter, False)

    return data